package cn.lds.j367.dsbank.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SysExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {


        SysException ex = null;

        if (e instanceof SysException){
            ex = (SysException) e;
        }else {
            e.printStackTrace();
            ex = new SysException("系统升级中……");
        }
        ModelAndView mv = new ModelAndView();
        //将异常信息放入Request对象
        mv.addObject("errorMsg",ex.getMsg());

//        e.printStackTrace();

        //转发请求到error.jsp页面
        mv.setViewName("error");

        return mv;
    }
}
